package com.example.weather.utils;

import com.example.weather.pojo.CityWeather;
import com.example.weather.pojo.CityWeatherGeneral;
import com.google.gson.Gson;

import java.io.IOException;

import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

public class WeatherUtil {
    public static CityWeather getWeatherForCity(String cityName,String token) throws IOException {

        OkHttpClient client = new OkHttpClient().newBuilder()
                .build();
        Request request = new Request.Builder()
                .url(BaseUrl.baseUrl+"/dev-api/bs-weather-report/weather/getCurrentDayData/"+cityName)
                .get()
                .addHeader("Authorization", "Bearer "+token)
                .build();
        Response response = client.newCall(request).execute();
        Gson gson = new Gson();
        CityWeatherGeneral cityWeatherGeneral = gson.fromJson(response.body().string(), CityWeatherGeneral.class);
        return cityWeatherGeneral.getData();
    }
}
